package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import commoni.entity.UserInfo;
import commoni.interfaces.IUserInfoService;

import com.example.demo.mapper.UserInfoMapper;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author kt
 * @since 2021-02-05
 */
@Service
@com.alibaba.dubbo.config.annotation.Service
public class UserInfoServiceImpl implements IUserInfoService {

	@Resource
	private UserInfoMapper userInfoMapper;

	public int add(UserInfo userInfo) {
		return userInfoMapper.insert(userInfo);
	}

	public int del(Integer id) {
		return userInfoMapper.deleteById(id);
	}

	public int update(UserInfo userInfo) {
		UpdateWrapper<UserInfo> uw = new UpdateWrapper<>();
		uw.eq("id", userInfo.getId());
		uw.set("name", userInfo.getName());
		uw.set("desc_content", userInfo.getDescContent());
		return userInfoMapper.update(userInfo,uw);
	}

	public UserInfo find(Integer id) {
		UserInfo userInfo = userInfoMapper.selectById(id);
		return userInfo;
	}

	public Page<UserInfo> getPage(Page<UserInfo> page) {
		return userInfoMapper.selectPage(page, null);
	}

	public int add1000000(UserInfo userInfo) {
		int count = 0;
		for (int i = 0; i < 1000000; i++) {
			userInfo.setContent("content"+i);
			userInfo.setName("name"+i);
			count += userInfoMapper.insert(userInfo);
		}
		return count;
	}
}
